import * as api from "../../plugins/api.js"
import * as types from './mutation-types'

export const session = async function ({
  commit
}) {
  try {
    let data = await api.session()
    if (data.usertype == "Tourist") {
      data = false
      return data
    } else {
      commit(types.SET_U, data)
      return true
    }
  } catch (err) {
    throw (err)
  }
}

export const login = async function ({
  commit
}, datas) {
  try {
    let data = await api.asynclogin(datas)
    commit(types.SET_U, data)
    return data
  } catch (err) {
    throw (err)
  }
}

// export const actionAuth = async function ({
//   commit
// }) {
//   try {
//     let data = await api.getallcourse()
//   } catch (err) {
//     throw (err)
//   }
// }

export const actionCatebag = async function ({
  commit
}) {
  try {
    let data = await api.getAllCatebag()
    commit(types.SET_CATEBAG, data)
  } catch (err) {
    throw (err)
  }
}

export const actionCatebagtype = async function ({
  commit
}) {
  try {
    let data = await api.getAllCatebagtype()
    commit(types.SET_CATEBAGTYPE, data)
  } catch (err) {
    throw (err)
  }
}

export const actionCourse = async function ({
  commit
}) {
  try {
    let data = await api.getallcourse()
    commit(types.SET_COURSE, data)
  } catch (err) {
    throw (err)
  }
}

export const actionuserCourse = async function ({
  commit
}) {
  try {
    let data = await api.asyncgetktUser()
    commit(types.SET_USERCOURSE, data)
  } catch (err) {
    throw (err)
  }
}

export const actionuserUsercourse = async function ({
  commit
}) {
  try {
    let data = await api.asyncgetuserUsercourse()
    commit(types.SET_USERUSERCOURSE, data)
  } catch (err) {
    throw (err)
  }
}

export const actionagentUser = async function ({
  commit
}) {
  try {
    let data = await api.asyncgetChildren()
    commit(types.SET_AGENTUSER, data)
  } catch (err) {
    throw (err)
  }
}

export const actionagentInvite = async function ({
  commit
}) {
  try {
    let data = await api.asyncgetInvite()
    commit(types.SET_AGENTINVITE, data)
  } catch (err) {
    throw (err)
  }
}

export const actionmedals = async function ({
  commit
}) {
  try {
    let data = await api.asyncgetUserAllPoint()
    commit(types.SET_MEDALS, data)
  } catch (err) {
    throw (err)
  }
}

// export const actionIframe = async function ({
//   commit
// }) {
//   try {
//     let data = await api.asyncgetUserAllPoint()
//     commit(types.SET_IFRAME, data)
//   } catch (err) {
//     throw (err)
//   }
// }

export const actionCoursecatebag = async function ({
  commit
}) {
  try {
    let data = await api.asyncgetcoursecatebag();
    commit(types.SET_COURSECATEBAG, data);
  } catch (err) {
    throw (err)
  }
}